#ifndef JSMF_CREATER_JSMF_H
#define JSMN_CREATER_JSMF_H

#include "stdint.h"

typedef int jsmf_obj;

#define MAX_TOK_STACK_LEN 128

typedef enum {
    JSMF_END_TOK = 0,
    JSMF_OBJECT = 1 << 0,
    JSMF_ARRAY = 1 << 1,
    JSMF_STRING = 1 << 2,
    JSMF_PRIMITIVE = 1 << 3
} jsmftype_t;

#pragma anon_unions
typedef struct {
    char *name;
    union {
        char *str;
        int num;
    };
    jsmftype_t type;
    uint8_t parent;
} jsmftok_t;

typedef struct {
    jsmftok_t *tokBuf;
    uint16_t tokNum;
    int tokRoot; /* superior token node, e.g. parent object or array */
    uint8_t tokNext;
    uint8_t tokStack[MAX_TOK_STACK_LEN];
    uint8_t stacki;
} jsmf_creater;

jsmf_obj JsmfInitRoot(jsmftok_t *tokBuf, uint8_t maxLen);
int AddObjToObject(jsmf_obj object, char * name);
int AddObjToArray(jsmf_obj object);
int AddArrToObject(jsmf_obj object, char * name);
int AddStringToObject(jsmf_obj object, char * name, char * string);
int AddNumToObject(jsmf_obj object, char * name, const int number);
int AddStringToArray(jsmf_obj object, char * string);
int AddNumToArray(jsmf_obj object, const int number);
int PrintJsonStr(jsmf_obj object, char *buf, int len);

#endif //JSMF_CREATER_JSMF_H
